<?php
// Số người đang online
$tg=time();
$tgout=1800;
$tgnew = $tg - $tgout;
$remote_addr = $_SERVER['REMOTE_ADDR'];
$php_self = $_SERVER['PHP_SELF'];
$insert_online = new db_execute('INSERT INTO useronline(tgtmp,ip,local) VALUES('.$tg.',"'.$remote_addr.'","'.$php_self.'")');
unset($insert_online);
$delete_online = new db_execute('DELETE FROM useronline WHERE tgtmp < '.$tgnew.'');
unset($delete_online);
$query = new db_count('SELECT count(DISTINCT ip) as count FROM useronline WHERE local="'.$php_self.'"');
$access_user = $query->total;
unset($query);

//
$accsess_time = getdate();
$acc_day = $accsess_time['mday'];
$acc_month = $accsess_time['mon'];
$acc_year = $accsess_time['year'];
if(!isset($_SESSION['access_ip'])) {
    $_SESSION['access_ip'] =  $remote_addr;
    $insert_access = new db_execute('INSERT INTO access_counter(acc_ip,acc_day,acc_month,acc_year) VALUES("'.$remote_addr.'",'.$acc_day.','.$acc_month.','.$acc_year.')');
    unset($insert_access);
}
$query_day = new db_count('SELECT count(acc_ip) as count FROM access_counter WHERE acc_day = '.$acc_day.' AND acc_month = '.$acc_month.' AND acc_year = '.$acc_year.'');
$accsess_day = $query_day->total;
unset($query_day);
$query_month = new db_count('SELECT count(acc_ip) as count FROM access_counter WHERE acc_month = '.$acc_month.' AND acc_year = '.$acc_year.'');
$accsess_month = $query_month->total;
unset($query_month);
$query_total = new db_count('SELECT count(acc_ip) as count FROM access_counter WHERE 1 ');
$accsess_total = $query_total->total;
unset($query_total);
?>